<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<% 
String path=request.getContextPath(); 
String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; 
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<base href="<%=basePath%>">
<title>方案配置</title>
<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
<script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>

<style type="text/css">
		#detail
        {
            position:relative;
            width: 200px;
            font-size: 12px;
            background: #fff;
            border: 1px solid #000;
            z-index: 2;
            display: none;
        } 
        #detail2
        {
            position:relative;
            width: 200px;
            font-size: 12px;
            background: #fff;
            border: 1px solid #000;
            z-index: 2;
            display: none;
        } 
	.input_fxk {width: 15px;height: 15px;}
</style>
<script type="text/javascript">
	var startP = 1; //1 代表当前页，主页面默认展示第1页
	$(document).ready(function() {
		//初始读取数据
		loadInsuPlan({});
		<%if(null!=request.getAttribute("flag")){
		if("edittrue".equals(request.getAttribute("flag").toString())){
		%>	
			$.message("success","修改成功");
		<%}
		if("addtrue".equals(request.getAttribute("flag").toString())){
		%>
			$.message("success","添加成功");
		<%}}%>
	});
	
	//绑定单选按钮事件，选中某个单选按钮，该按钮所在行高亮显示
	function bindradio(){
		$("input[name='radioInsuplan']").click(function(){
			$("input[name='radioInsuplan']").parent().parent().removeClass("table_highlighter");
			$(this).parent().parent().addClass("table_highlighter");
       	});
		$("input[name='partnerradio']").click(function(){
			$("input[name='partnerradio']").parent().parent().removeClass("table_highlighter");
			$(this).parent().parent().addClass("table_highlighter");
       	});
	}

	/**
	* 投保方案名称
	*/
	 function showDatail(obj){
			var result=obj.innerHTML;
			if(result!=""){
				 var length =obj.scrollWidth;
				 if(length>240){
				 	var e = arguments.callee.caller.arguments[0]||window.event;
				 	var y = e.clientY;
				 	var x= document.body.offsetWidth;
				 	if(x>460){
				 		x=x-770;
				 	}
				 	var div3 = document.getElementById("detail");   
				 	document.getElementById("detail").style.display = 'block';
				 	div3.style.left=x;     
		            div3.style.top=e.clientY+1+document.body.scrollTop;  
		            div3.style.position="absolute";
				 	$("#input")[0].innerHTML=result;
				 }
			}
		}
	 function copyDetail(obj){
			var result=obj.innerHTML;
			if(result!=""){
				 var length =obj.scrollWidth;
				 if(length>0){
				 	var e = arguments.callee.caller.arguments[0]||window.event;
				 	var y = e.clientY;
				 	var x= document.body.offsetWidth;
				 	if(x>460){
				 		x=x-770;
				 	}
				 	var div3 = document.getElementById("detail2");   
        	 		document.getElementById("detail2").style.display = 'block';
				 	div3.style.left=x;     
		            div3.style.top=e.clientY+1+document.body.scrollTop;  
		            div3.style.position="absolute";
				 	$("#output")[0].innerHTML=result;
				 }
			}
		}
	 
	 function closeDatail(){
		 document.getElementById("detail").style.display = 'none';
	 }
	 function closeDiv(){
		 document.getElementById("detail2").style.display = 'none';
 	 }
	/*--------------------------------------------------------------------------------*/
	function showDatail2(obj){
			var result=obj.innerHTML;
			if(result!=""){
				 var length =obj.scrollWidth;
				 if(length>240){
				 	var e = arguments.callee.caller.arguments[0]||window.event;
				 	var y = e.clientY;
				 	var x= document.body.offsetWidth;
				 	if(x>460){
				 		x=x-460;
				 	}
				 	var div3 = document.getElementById("detail");   
				 	document.getElementById("detail").style.display = 'block';
				 	div3.style.left=x;     
		            div3.style.top=e.clientY+1+document.body.scrollTop;  
		            div3.style.position="absolute";
				 	$("#input")[0].innerHTML=result;
				 }
			}
		}
	 function copyDetail2(obj){
			var result=obj.innerHTML;
			if(result!=""){
				 var length =obj.scrollWidth;
				 if(length>0){
				 	var e = arguments.callee.caller.arguments[0]||window.event;
				 	var y = e.clientY;
				 	var x= document.body.offsetWidth;
				 	if(x>460){
				 		x=x-460;
				 	}
				 	var div3 = document.getElementById("detail2");   
        	 		document.getElementById("detail2").style.display = 'block';
				 	div3.style.left=x;     
		            div3.style.top=e.clientY+1+document.body.scrollTop;  
		            div3.style.position="absolute";
				 	$("#output")[0].innerHTML=result;
				 }
			}
		}
	 
	 function closeDatail2(){
		 document.getElementById("detail").style.display = 'none';
	 }
	 function closeDiv2(){
		 document.getElementById("detail2").style.display = 'none';
 	 }
	 
	 
	//为查询投保方案 拼接参数
	function queryInsuPlan(displayPage){
		var pno = $('#tradPartnerNo').val();
		var planCode = $('#planCode').val();
		var planName = $('#planName').val();
		var prodCode= $('#prodCode').val();
		loadInsuPlan({current:displayPage,size:10,prodCode:prodCode,partnerCode:pno,planCode:planCode,planName:planName});
	}
	
	//加载投保方案
	var isExpFlag= false;
	function loadInsuPlan(param){
		$.openLoading();
			$.ajax({
					url : "noCarInsure/loadInsuPlan",
					type : 'POST',
					async : true,
					dataType:'json',
					data:param,
					success : function(page) {
						$.closeLoading();
						if($.validate(page))return;
							startP = page.current;
							isExpFlag =page.obj;
							//alert(isExpFlag);
							var firstbutton='';
							if(isExpFlag){
								firstbutton ="<input class='input_fxk' name='radioInsuplan' type='radio' value='#'>@<input class='input_fxk' name='checkInsuplan' type='checkBox' value='#'>";
								$("#expPlanBtn").show();
							}else{
								firstbutton ="<input class='input_fxk' name='radioInsuplan' type='radio' value='#'>";
								$("#expPlanBtn").hide();//根据用户显示按钮和导出复选框
								if($('#InsuPlanTable tr th:eq(1)').html()=="导出"){
									$('#InsuPlanTable tr th:eq(1)').remove();
								}
							}
							var lastbutton = "<a href='javascript:void(0)' onClick='edit(this);return false'>编辑</a>&nbsp;<a href='javascript:void(0)' onClick='warnDelInsuplan(this);return false'>删除</a>";
// 							<a href='javascript:void(this)' style='font-size:12px;display: block;overflow: hidden;white-space: nowrap;text-align:center;-o-text-overflow: ellipsis;text-overflow: ellipsis;width:240px;font-family:宋体;font-weight:normal' onDblClick='copyDetail(this);' onclick='showDatail(this);return false' onmouseover='showDatail(this);return false' onmouseout='closeDatail(this);return false'>partnerName</a>
							var tableContent = creatTable1("planCode,planName,prodType@TDH,prodCode,prodName,partnerCode,partnerDesc",page,firstbutton,lastbutton);
							var tableObj = $("#InsuPlanTable");
							tableObj.find("tbody").remove();
							tableObj.append(tableContent);
							var strPage = creatChannelPage(startP,6,page.maxPage,"15");
							var pageDIV = $("#InsuPlanPageDIV");
							pageDIV[0].innerHTML="";
							pageDIV.append(strPage);
							bindradio();//点击单选按钮，该行高亮显示	
					}
				});
		}
	
	
	//删除投保方案前 弹出提示框
	function warnDelInsuplan(obj){
		$.dialog({
			type: "warn",
			content: "您确定要删除该投保方案吗？",
			onOk: function() {
				delTradInstPlan(obj);
			}
		});
	}
	
	//删除投保方案
	function delTradInstPlan(obj){
		$.openLoading();
		var delTr = $(obj).parent('td').parent('tr')[0];
		var planCodeFlag=1;
		var channelCodeValFlag=5;
		if(isExpFlag){
			planCodeFlag = 2;
			channelCodeValFlag=6;
		}
		var planCode = delTr.childNodes[planCodeFlag].innerHTML;
		var channelCodeVal = delTr.childNodes[channelCodeValFlag].innerHTML;
		$.ajax({
			url: "noCarInsure/delInsuPlan",
			type: "post",
			dataType: "json",
			data:{planCode:planCode,channelCode:channelCodeVal},
			async:true,
			cache:false,
			success: function(data) {
				$.closeLoading();
				if($.validate(data))return;
				queryInsuPlan(1);
			}
		});
	}
	
	
	//跳转至 投保方案 编辑 页面 并展示方案信息
	function edit(obj){
		var delTr = $(obj).parent('td').parent('tr')[0];
		var flag=1;
		if(isExpFlag){
			flag = 2;
		}
		var planCode = delTr.childNodes[flag].innerHTML;
		window.location.href='<%=path%>/noCarInsure/edit?planCode='+planCode;
	}
	
	
	//跳转至添加 投保方案 页面
	function add(){
		window.location.href='<%=path%>/noCarInsure/add';
	}
	

//关闭  窗口
function closeCurrentDIV(obj){
		$("#"+obj).CloseDiv();	
}

//initTradPartners
function queryPartner(param){
	$.openLoading();
	$.ajax({
		url : "noCarInsure/loadChannelInfo",
		type : 'POST',
		async : true,
		data:param,
		dataType:'json',
		success:function(partnerPage){
			$.closeLoading();
			if($.validate(partnerPage))return;

					var radioObj ="<input class='input_fxk' name='partnerradio' type='radio' value=''>";
					var fieldNames = "channelCode@TDH,channelCode,channelName";
					var tableContent = creatTable1(fieldNames,partnerPage,radioObj);
					var tableObj = $("#TradPartnerTable");
					tableObj.find("tbody").remove();
					tableObj.append(tableContent);
					
					var strPage = creatChannelPage2(param.pageIndex,6,partnerPage.maxPage,"16");
					var pageDIV = $("#TradPartnerPageDIV");
					pageDIV[0].innerHTML="";
					pageDIV.append(strPage);
					
					$('#tradPartnerDiv').OpenDiv();
					
					bindradio();
			}
	});
	
}  



//打开 div 方法
function openThisDiv(divObj,pageIndex,cur){
	$("#"+cur.id).blur();
	queryTradPartners(pageIndex);
}


//拼接页面查询参数  查询投保单位
function mergePartnerParams(pageIndex){
	var size = 8;
	var channelCode = $('#channelCode').val();
	var channelName = $('#channelName').val();
	queryPartner({pageIndex:pageIndex,size:size,channelCode:channelCode,channelName:channelName});
}



//查询 投保单位
function queryTradPartners(pageIndex){
	mergePartnerParams(pageIndex);
}


//点击“确定”按钮，选择投保单位
function choosePartner(){
	var selectedPartner = $("input[name='partnerradio']:checked");
	if(selectedPartner.length==0){
		$.message("error", "请选择一个投保单位");
		return;
	}
	var pno = selectedPartner.parent().parent().children(" td:eq(1)").html();
	var pname = selectedPartner.parent().parent().children(" td:eq(3)").html();
	$('#tradPartnerName').val(pname);
	$('#tradPartnerNo').val(pno);
	closeCurrentDIV('tradPartnerDiv');
}

//点击”重置“，清空查询条件
function clearParams(){
	$('#tradPartnerNo').val('');
	$('#tradPartnerName').val('');
	$('#planCode').val('');
	$('#planName').val('');
}



//复制添加 功能
function copyAdd(){
	var selInsuplan = $("input[name='radioInsuplan']:checked");
	if(selInsuplan.length==0){
		$.message("error", "请选择一个投保方案");
		return;
	}
	var insuplanSelobjFlag=1;
	var prodTypeFlag=3;
	if(isExpFlag){
		insuplanSelobjFlag = 2;
		prodTypeFlag = 4;
	}
	var insuplanSelobj = $(selInsuplan).parent('td').parent('tr')[0].childNodes[insuplanSelobjFlag].innerHTML;
	var prodType = $(selInsuplan).parent('td').parent('tr')[0].childNodes[prodTypeFlag].innerHTML;
	window.location.href='<%=path%>/noCarInsure/copyadd?planCode='+insuplanSelobj+'&prodType='+prodType;
}
//导出方案数据
function expPlan(){
	var selInsuplan = $("input[name='checkInsuplan']:checked");
	//alert(selInsuplan);
	if(selInsuplan.length==0){
		$.message("error", "请至少选择一个方案");
		return;
	}
	var planCode='';
	$(selInsuplan).each(function(){
		if(''==planCode){
			planCode=$(this).parent().parent().children("td:eq(2)").html()
		}else{
			planCode=planCode+','+$(this).parent().parent().children('td:eq(2)').html();
			//alert(planCode);
		}
	})
	window.location.href='<%=path%>/noCarInsure/expPlan?planCode='+planCode;
}
	</script>
</head>
<body>
<div class="current">
           <table class="current_table_1">
              <tbody>
                <tr class="f2">
                  <td>
                    <img src="./images/current_1.jpg">
                  </td>
                  <td class="current_table_1_td">
                    <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                      <span style=" color:#136bab; ">财险产品管理
                      <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>方案配置
                  </span>
                  </td>
                  <td><img src="./images/current_3.jpg"></td>
              </tr>
           </tbody>
         </table>
      </div>
	<table class="table_02" id="table">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td width="32%" height="30">
								<div style="display: inline-block;">
									合作伙伴代码：
									<input name="txt3"  id="tradPartnerNo" value="" readonly="readonly" style="width:130px;background: #ccc;" class="input_text" >
									<input type="button"  class="input_button_1" id="searchPartner" value="选择" onClick="openThisDiv('tradPartnerDiv',1,this)"/>
								</div>
							</td>
							<td width="23%" height="30">产品编号：
								&nbsp;&nbsp;<input name="txt3" id="prodCode" type="text" class="input_text" value="" >
							</td>
							</tr>
							<tr height="30px">
							<td width="23%" height="30">投保方案号：
						 		&nbsp;<input name="txt3" id="planCode"  type="text" class="input_text" value="" >
							</td>
							<td width="30%" height="30">投保方案名称：
								<input name="txt3" id="planName"  type="text"  class="input_text" value="" >
							</td>
							<td width="15%" height="30">
								<input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="queryInsuPlan(1)"/>&nbsp;
								<input type="button" value="重置" onClick="clearParams()" class="input_button_1" />							
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
						<table class="search_table">
							<tr height="30px">
								<td width="100%" height="30">
									 <input type="button"  class="input_button_1" id="searchBtn" value="新增" onClick="add()"/>&nbsp;
									 <input type="button"  class="input_button_2" id="copyAddBtn" value="复制新增" onClick="copyAdd()"/>&nbsp;
									 <input type="button"  class="input_button_2" id="expPlanBtn" value="方案导出" onClick="expPlan()"/>
								</td>
							</tr>
						</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="InsuPlanTable"  class="content_table_1">
						<thead>
							<tr class="f1">
			                  <th style="width:5%">选择</th>
			                  <th style="width:5%">导出</th>
			                  <th style="width:9%">投保方案号</th>
			                  <th style="width:20%">投保方案名称</th>
			                  <th style="width:9%">产品编号</th>
			                  <th style="width:20%">产品名称</th>
			                  <th style="width:9%">合作伙伴代码</th>
			                  <th style="width:15%">合作伙伴名称</th>
			                  <th style="width:13%">操作</th>
			              	</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="InsuPlanPageDIV"  class="page"></div>
				</td>
			</tr>
		</table>
	  				 	  				 


	<!--   	选择 投保单位 div-->
  		<div id="tradPartnerDiv" style="display:none;width:90%;text-align: center;">
		<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeCurrentDIV('tradPartnerDiv')"/></td>
						</tr>
					</table>
			</div>
		<table class="table_02" id="table" style="width:98%">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td colspan="3" style="text-align:center">合作伙伴代码：<input name="txt3"  id="channelCode"  type="text" class="input_text" value="" >
								&nbsp;&nbsp;合作伙伴名称：<input name="txt3" id="channelName"  type="text" class="input_text" value="">
								&nbsp;&nbsp;<input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="queryTradPartners(1)"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="TradPartnerTable"  class="content_table_1">
						<thead>
							<tr class="f1">
			                  <th style="width:5%">选择</th>
			                  <th style="width:10%">合作伙伴代码</th>
			                  <th style="width:20%">合作伙伴名称</th>
			              	</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="TradPartnerPageDIV"  class="page"></div>
				</td>
			</tr>
		</table>
		<div align="center">
		   <input type="button" id="saveRoleBtn" value="确定" onclick="choosePartner()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
		   <input type="button" value="取消" onclick="closeCurrentDIV('tradPartnerDiv')" class="input_button_3"/>
		</div>
	</div>	
	
<div id="detail" style="display:none;">
			<div id="input" style="margin:5px;word-wrap:break-word;"></div>
		</div>
		<div id="detail2" style="display:none;">
			<h4  style='background-color:#A4BDE3;'>
				<table height="20px">
					<tr>
					    <td width="200px";>
					    </td>
					    <td align="right">
					       <img src="./images/closedown.gif"  onclick="closeDiv()"/>
					    </td>
					</tr>							
				</table>
				<input type="hidden" id="appId" value="">
			</h4>	
			<div id="output" style="margin:5px;word-wrap:break-word;"></div>
		</div>

</body>
</html>